<?php

class BookCreateAction extends CAction
{
    public function run()
    {
		$model=new Book;

		// Uncomment the following line if AJAX validation is needed
		// $this->performAjaxValidation($model);

		if(isset($_POST['Book']))
		{
			$model->attributes=$_POST['Book'];
			
			$model->uid=1;
			$model->username='admin';
			
			$uploadFile = CUploadedFile::getInstance($model, 'image_url');
			if($uploadFile !== null){
				$uploadFileName = time() . '.' . $uploadFile->getExtensionName();
				$model->image_url = $uploadFileName;
			}
			$model->createtime=time();
			
			if($model->save()){
				if($uploadFile !== null)
					$uploadFile->saveAs(Yii::app()->basePath.'/../upload/'.$uploadFileName);
				$this->controller->redirect(array('view','id'=>$model->id));
			}
		}

		$this->controller->render('/book/create',array(
			'model'=>$model,
		));
	}
}
?>